package com.platform.modules.app.controller;

import com.platform.common.utils.RestResponse;
import com.platform.modules.sys.entity.SysUserEntity;
import com.platform.modules.sys.service.SysUserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

/**
 * 用户个人信息接口
 */
@Slf4j
@RestController
@RequestMapping("/app/user")
public class AppUserController {

    @Autowired
    private SysUserService sysUserService;

    @GetMapping("/userInfo")
    public RestResponse userInfo(HttpServletRequest request){
        // 加了注解@Slf4j即可在类中使用log对象
        log.info("#########  info  #########");
        log.debug("#########  debug  #########");
        log.error("#########  error  #########");

        Map<String, Object> map = new HashMap<>();
        String userId = (String) request.getAttribute("LOGIN_USER_KEY");
        SysUserEntity sysUserEntity = sysUserService.queryByUserId(userId);
        map.put("userId",userId);
        map.put("userName",sysUserEntity.getRealName());
        return RestResponse.success(map);
    }
}
